package com.luo;

import org.apache.commons.codec.digest.DigestUtils;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.FilePipeline;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.io.*;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class MyFilePipeline extends FilePipeline {

    @Override
    public void process(ResultItems resultItems, Task task) {
        setPath("F:/book");
        //super.process(resultItems, task);
        String path = this.path + PATH_SEPERATOR + task.getUUID() + PATH_SEPERATOR;

        PrintWriter printWriter = null;
        try {
            printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(this.getFile(path + resultItems.get("bookName").toString() + ".txt"),true), "GBK"));
            // printWriter.println("url:\t" + resultItems.getRequest().getUrl());
            List<String> var5 = (List<String>) resultItems.get("content");
            printWriter.println(resultItems.get("title"));
            for (String con : var5) {
                printWriter.println(con);
            }
            printWriter.close();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

}
